package com.ym.manager.admin.t3;

import com.ym.manager.admin.act.model.Act;
import com.ym.manager.admin.t3.model.T3Info;
import com.ym.utils.DateUtil;
import com.ym.utils.Pages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class T3Model {

    @Autowired
    private T3Mapper t3Mapper;

    //列表数据
    public Pages<T3Info> listData(int pageNum, int limit, int merchant_id, String title, int status) {
        Map<String,Object> map = new HashMap<>();
        int begin = (pageNum-1)*limit;
        map.put("begin",begin);
        map.put("limit",limit);
        map.put("merchant_id",merchant_id);
        map.put("title",title);
        map.put("status",status);
        int count  = t3Mapper.getListCount(map);
        List<T3Info> list = t3Mapper.getList(map);
        Pages<T3Info> pages = new Pages<>(count,pageNum,limit);
        pages.setList(list);
        return pages;
    }

    //新增数据
    public int insert(T3Info t3Info) {
        t3Info.setCreateTime(DateUtil.getDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
        return t3Mapper.insert(t3Info);
    }

    //修改数据
    public int update(T3Info t3Info) {
        t3Info.setUpdateTime(DateUtil.getDate(new Date(),"yyyy-MM-dd HH:mm:ss"));
        return t3Mapper.update(t3Info);
    }

    //数据详情
    public T3Info detail(int id) {
        return t3Mapper.detail(id);
    }

    //活动上下架
    public int shelf(int id, int status) {
        return t3Mapper.shelf(id,status);
    }

    //删除活动
    public int delete(int id) {
        return t3Mapper.delete(id);
    }

    //预约列表
    public Pages<Map<String, Object>> subscribeDetail(int pageNum, int limit, int id) {
        Map<String,Object> map = new HashMap<>();
        int begin = (pageNum-1)*limit;
        map.put("begin",begin);
        map.put("limit",limit);
        map.put("id",id);
        int count  = t3Mapper.getSubscribeCount(map);
        List<Map<String,Object>> list = t3Mapper.getSubscribe(map);
        Pages<Map<String,Object>> pages = new Pages<>(count,pageNum,limit);
        pages.setList(list);
        return pages;
    }

    public int subscribeArrival(int uid,int actId, int status) {
        return t3Mapper.subscribeArrival(uid,actId,status);
    }
}
